package com.itheima.d5_resource;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：掌握释放资源的方式。
 */
public class Test2 {

    public static void main(String[] args)  {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("D:\\p图\\孙\\脸部.jpg");
            fos = new FileOutputStream("a.jpg");

            int len;
            byte[] bytes = new byte[1024];
            while((len = fis.read(bytes)) != -1){
                fos.write(bytes, 0, len);
            }
            fos.close();
            fis.close();
        } catch (Exception e) {
           e.printStackTrace();
        }finally {
            try {
                fos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            try {
                fis.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
